﻿using System.Windows;
using Red.Controls.Shell;
using Database = Red.Launcher.ViewModels.Workspaces.Database;
using Dialog = Red.Launcher.Utilities.Dialog;
using P4 = Red.Core.Perforce;

namespace Red.Launcher.Menus.Workspaces.Admin
{
    public partial class SpecificationsDialog : RedWindow, Dialog.IEvents, Dialog.IData
    {
        #region Public Properties

        public Database.P4ClientSpecification P4ClientSpecification
        {
            get { return DataContext as Database.P4ClientSpecification; }
            set { DataContext = value; }
        }

        #endregion Public Properties

        #region C-Tor

        public SpecificationsDialog()
        {
            InitializeComponent();

            Loaded += Window_Loaded;
        }

        #endregion C-Tor

        #region Event Handlers

        void Window_Loaded( object sender, RoutedEventArgs e )
        {
            MinHeight = ActualHeight;
        }

        private void OK_Click( object sender, RoutedEventArgs e )
        {
            _specifications.RefreshBindingsForValidation();
            if ( _specifications.IsValid )
            {
                Ok?.Invoke();
                Close();
            }
        }

        private void Cancel_Click( object sender, RoutedEventArgs e )
        {
            Close();
        }

        #endregion Event Handlers

        #region IEvents

        public bool Propagated { get; set; }
        public event Dialog.InterfaceClosed Ok;

        #endregion IEvents

        #region IData

        public object Data { get { return _specifications.Mediator; } set { _specifications.Mediator = value as P4.Mediator; } }

        #endregion IData
    }
}
